package com.dailyblue.example.project.bookstore.user.controller;

import com.alibaba.fastjson.JSONArray;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.dailyblue.example.project.bookstore.commons.bean.Alipay;
import com.dailyblue.example.project.bookstore.commons.bean.Logistics;
import com.dailyblue.example.project.bookstore.user.service.AlipayService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/alipay")
public class AlipayController {
    @Value("${alipay.appId}")
    private String appId;
    @Value("${alipay.privateKey}")
    private String privateKey;
    @Value("${alipay.publicKey}")
    private String publicKey;
    @Value("${alipay.signType}")
    private String signType;
    @Value("${alipay.charset}")
    private String charset;
    @Value("${alipay.gatewayUrl}")
    private String gatewayUrl;
    @Value("${alipay.notifyUrl}")
    private String notifyUrl;
    @Value("${alipay.returnUrl}")
    private String returnUrl;
    @Resource
    private AlipayService service;

    @GetMapping("/success")
    public String success() {
        return "Success";
    }

    @PostMapping
    public String alipay(Logistics logistics, String json) throws AlipayApiException {
        return service.alipay(appId, privateKey, publicKey, signType, charset, gatewayUrl, notifyUrl, returnUrl, logistics, json);
    }
}
